    layui.use(['upload','element'], function(){
       	var element = layui.element;
    	var upload = layui.upload;
       
        $(function () {
        	var dateTimer=setInterval(function () {
                $("#importTime").val(getDateFormat());
            },1000);
            
            upload.render({
                elem: '#file'
                ,url: 'fileUpload'
                ,accept:'file'
                ,exts:'xlsx|xls'
                ,size:1024
            	,before:function(obj){
                    obj.preview(function(index, file, result){
                        $("#fileName").val(file.name);
                    });
                   $("#icon-upload").html("<i class=\"layui-icon layui-anim layui-anim-rotate layui-anim-loop icon_upload\">&#xe63d;</i>");
            	}
                ,done: function(res){
                    if (res.success) {
                    	$("#icon-upload").html("<i class=\"layui-icon icon_upload\">&#xe610;</i>");
					}else {
						$("#icon-upload").html("<i class=\"layui-icon icon_upload\">&#xe69c;</i>");
					}
                }
                ,error: function(){
                    layer.alert("请求异常，请重试");
                }
            });
            
            $("#startImport").click(function () {
            	var fileName=$("#fileName").val();
            	if (fileName=="") {
            		layer.tips('请先上传文件', '#fileName', {
            			  tips: [1, '#0FA6D8']
            			});
				}else{
					clearInterval(dateTimer);
					var n=0;
		        	var timer = setInterval(function(){
		        		n+=20;
		                element.progress('demo', n+'%');
		                if (n>=100) {
		                	clearInterval(timer);
						}
		            },500);
		        	
					$.ajax({
						url:"importStudent",
						type:"POST",
						data:"fileName="+fileName,
						success:function(res){
							clearInterval(timer);
							element.progress('demo', '100%');
							if (res.success) {
								setTimeout(() => {
									layer.alert("导入成功",function(){
				                		window.location.reload();
				                	});
								}, 500);
							}else{
								setTimeout(() => {
									layer.alert("导入异常，请检查文件格式是否正确",function(){
				                		window.location.reload();
				                	});
								}, 500);
							}
						}
					});
				}
        		return false;
			});
            
            $("#template").click(function () {
				window.location="template";
			});
        });
        
        function getDateFormat() {
            var date=new Date();
            return date.getFullYear()+"-"+
            timePlus((date.getMonth()+1))+"-"+
            timePlus(date.getDate())+" "+
         	timePlus(date.getHours())+":"+
            timePlus(date.getMinutes())+":"+
            timePlus(date.getSeconds());
        }
        
        function timePlus(num) {
			if (num<10) {
				return "0"+num;
			}
			return num;
		}
        
    });